package com.chenjinyan.back.controller;

import com.chenjinyan.back.service.UserService;
import com.chenjinyan.back.utils.ExceptionHandle;
import com.chenjinyan.back.utils.ResultUtil;
import com.chenjinyan.back.vo.Result;
import com.chenjinyan.back.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private ExceptionHandle exceptionHandle;

    @Autowired
    UserService userService;

    @PostMapping("/getUserInfo")
    public Result getUserInfo(@RequestBody User user) {
        Result result = ResultUtil.success();
        try {
            //查找用户
            result = userService.findUser(user);
        } catch (Exception e) {
            result = exceptionHandle.exceptionGet(e);
        }
        return result;
    }

    @PostMapping("/delUser")
    public Result delUser(@RequestBody List<String> userIds) {
        Result result = ResultUtil.success();
        try {
            //查找用户
            result = userService.delUser(userIds);
            return result;
        } catch (Exception e) {
            result = exceptionHandle.exceptionGet(e);
        }
        return result;
    }



}
